package top.soulblack.purchasesale.mapper;

import org.apache.ibatis.annotations.*;
import top.soulblack.purchasesale.model.GoodsColor;

import java.util.List;

@Mapper
public interface GoodsColorMapper {

    List<Integer> deleteById(Integer id);

    int insert(GoodsColor record);

    int insertSelective(GoodsColor record);

    GoodsColor selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(GoodsColor record);

    int updateByPrimaryKey(GoodsColor record);

    List<GoodsColor> selectGoodsColorIdByBarCode(@Param("barCode") String barCode);

    @Select("select * from goods_color order by sort")
    List<GoodsColor> selectAll();

    @Select("select distinct `group` from goods_color")
    List<String> selectGroups();

    @Insert("insert into goods_color (name, `group`, sort, status) values (#{name}, #{group}, #{sort}, #{status})")
    void addColor(GoodsColor goodsColor);

    @Select("select count(*) from goods_color where name = #{name}")
    int existColor(String name);

    @Select("select * from goods_color where name = #{colorName} order by sort")
    List<GoodsColor> selectForName(@Param("colorName") String colorName);

    @Select("select * from goods_color where `group` = #{group} order by sort")
    List<GoodsColor> selectForGroup(@Param("group") String group);

    @Update("update goods_color set `group` = #{ngroup} where `group` = #{ogroup}")
    int updateGroup(@Param("ngroup") String ngroup, @Param("ogroup") String ogroup);

    @Update("update goods_color set `group` = '' where `group` = #{ogroup}")
    int deleteGroup(@Param("ogroup") String oldGroup);

    @Select("select color from goods where color = #{id}")
    List<Integer> selectColor(@Param("id") Integer id);
}